<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@page import="org.springframework.core.io.ClassPathResource"%>
<%@page import="org.springframework.beans.factory.xml.XmlBeanFactory"%>
<%@page import="com.zenika.zencontact.model.ContactDao"%>
<%@page import="com.zenika.zencontact.model.Contact"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.SimpleDateFormat"%>
<%
out.println("Adding customer...<br>");

	ClassPathResource res = new ClassPathResource(
			"applicationContext.xml");
	XmlBeanFactory factory = new XmlBeanFactory(res);
	ContactDao dao = (ContactDao) factory.getBean("jdbcContactDao");

	try {
		Contact newContact = new Contact();
		boolean active = Integer.parseInt(request.getParameter("active"))!=0;
		newContact.setActive(active);
		//SimpleDateFormat sdf = new SimpleDateFormat("JJ/MM/AAAA");
		//newContact.setBirthDate(sdf.parse(request.getParameter("birthDate")));
		newContact.setBirthDate(new Date());
		newContact.setCategory(request.getParameter("category"));
		newContact.setEmail(request.getParameter("email"));
		newContact.setFirstName(request.getParameter("firstName"));
		newContact.setLastName(request.getParameter("lastName"));
		newContact.setLanguage(request.getParameter("language"));
		newContact.setNotes(request.getParameter("notes"));
		dao.save(newContact);

	} catch (Exception e) {
		e.printStackTrace();
	};%>
